from django.db import models

from goods.models import GoodsModel
from user.models import UserModel, AddressModel


# Create your models here.

class OrderModel(models.Model):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name='用户')
    order_time = models.DateTimeField(auto_now_add=True, verbose_name="订单时间")
    total_price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="订单价格")
    status = models.IntegerField(verbose_name="订单状态", choices=((2, "货到付款"), (1, "在线支付")))
    order_no = models.CharField(max_length=100, verbose_name="订单号")
    pay_no = models.CharField(max_length=100, verbose_name="流水号", null=True, blank=True)
    p_time = models.DateTimeField(null=True, blank=True, verbose_name="支付时间")

    class Meta:
        db_table = "sxorder"


class DetailModel(models.Model):
    order = models.ForeignKey(OrderModel, on_delete=models.CASCADE, verbose_name="订单")
    goods = models.ForeignKey(GoodsModel, on_delete=models.CASCADE, verbose_name="商品")
    g_name = models.CharField(max_length=100, verbose_name="商品名称")
    number = models.IntegerField(verbose_name="数量")
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="价格")
    g_img = models.CharField(max_length=100, verbose_name="图片")

    class Meta:
        db_table = "sxdetail"


class MyGoodsModel(models.Model):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name='用户')
    goods = models.ForeignKey(GoodsModel, on_delete=models.CASCADE, verbose_name='商品')
    address = models.ForeignKey(AddressModel, on_delete=models.CASCADE, verbose_name='收货地址')
    g_name = models.CharField(max_length=100, verbose_name="商品名称")
    number = models.IntegerField(verbose_name="数量")
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="价格")
    g_img = models.CharField(max_length=100, verbose_name="图片")
    status = models.IntegerField(verbose_name="订单状态", choices=((2, "货到付款"), (1, "在线支付")))

    class Meta:
        db_table = "sxmygoods"
